package com.zhouchaoqun.web.api;

import com.google.common.collect.Lists;
import com.zhouchaoqun.web.contition2.ConditionLeafNode;
import com.zhouchaoqun.web.contition2.ConditionSetNode;
import com.zhouchaoqun.web.contition2.ConditionTreeNode;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhouchaoqun02
 * @date 2020-10-25 17:00
 */
@RestController
@RequestMapping("/cond")
public class ContitionDemoApi {

    @GetMapping("/")
    public ConditionTreeNode getConditionSet() {
        ConditionLeafNode cl1 = ConditionLeafNode.builder().property("a").operation("==").rValue("1").build();
        ConditionLeafNode cl2 = ConditionLeafNode.builder().property("b").operation("==").rValue("2").build();;
        ConditionLeafNode cl3 = ConditionLeafNode.builder().property("c").operation("==").rValue("3").build();

        ConditionSetNode subC1 = ConditionSetNode.builder().logical("&&").conditions(Lists.newArrayList(cl1, cl2)).build();

        return ConditionSetNode.builder().logical("||").conditions(Lists.newArrayList(cl3, subC1)).build();
    }

    @PostMapping("/")
    public String print(@RequestBody ConditionTreeNode conditionSet) {
        System.out.println(conditionSet);
        return "success";
    }
}
